package com.example.mybatisplusclass2.controller;

import com.example.mybatisplusclass2.entity.Student;
import com.example.mybatisplusclass2.entity.StudentCard;
import com.example.mybatisplusclass2.service.IStudentCardService;
import com.example.mybatisplusclass2.service.IStudentService;
import com.example.mybatisplusclass2.service.impl.StudentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author coolwen
 * @since 2024-04-30 14:20:03
 */
@Controller
@RequestMapping("studentcards")
public class StudentCardController {
    @Autowired
    IStudentCardService studentCardService;
    @GetMapping("/studentcardlist")
    public String listStudents(Model model) {
        List<StudentCard> StudentCards = studentCardService.list();
        model.addAttribute("StudentCards", StudentCards);
        return "studentcards/studentscardlist"; // 返回的视图名
    }
    @GetMapping("/{cid}")
    public String getStudentById(@PathVariable("cid") Integer cid, Model model) {
        StudentServiceImpl studentcardService = new StudentServiceImpl();
        Student student = studentcardService.getBalanceById(cid);
        model.addAttribute("student", student);
        return "students/studentDetails";
    }

}
